const state = {
    showEdit: false,
    dictId: 0,
    codeItems: []
};

const mutations = {
    Set_Show_Edit: (state, data) => {
        state.showEdit = data
    },
    Set_Dict_Id: (state, data) => {
        state.dictId = data
    },
    Set_Code_Items: (state, data) => {
        state.codeItems = data
    }
};

const actions = {
    showEditDict({commit}, dictId) {
        commit('Set_Show_Edit', true);
        commit('Set_Dict_Id', dictId);
    },
    setCodeItems({commit}, codeItems) {
        commit('Set_Code_Items', codeItems);
    },

    addCodeItem({state}, codeItem) {
        state.codeItems.push(codeItem)
    },

    deleteCodeItem({state}, codeItemId){
        for(let i = 0; i < state.codeItems.length; i++){
            if(codeItemId === state.codeItems[i].id){
                state.codeItems.splice(i, 1);
                break;
            }
        }
    },

    hideEditDict({commit}){
        commit('Set_Show_Edit', false);
    }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
